<?php
/*
	Plugin Name: SpeedUpForChina 
	Plugin URI:http://www.cwyyprog.com/speedupforchina/
	Description: 一、将谷歌字体、ajax库链接替换成360国内CDN链接,解决google在中国访问时常抽风影响到了google api和一些公共服务.二、头像加速，使用国内duoshuo镜像
	Version: 1.0
	Author: 窗外一叶
	Author URI: http://www.cwyyprog.com
*/
function cwyyprog_wordpress_callback($buffer) {
	$buffer=str_replace(array('http://ajax.useso.com/','http://ajax.useso.com/'),'http://ajax.useso.com/',$buffer);
	return str_replace(array('http://fonts.useso.com/css','http://fonts.useso.com/css',),'http://fonts.useso.com/css',$buffer);
}
function cwyyprog_buffer_start() {
	ob_start("cwyyprog_wordpress_callback");
}
function cwyyprog_buffer_end() {
	ob_end_flush();
}
add_action('init', 'cwyyprog_buffer_start');
add_action('shutdown', 'cwyyprog_buffer_end');
//头像加速，使用国内duoshuo镜像
function cwyyprog_wordpress_duoshuo_avatar($avatar) {

	// Replacement for the avatar URL, 头像URL替换为 gravatar.duoshuo.com 的域名.

	$avatar = str_replace(array("www.gravatar.com", "0.gravatar.com", "1.gravatar.com", "2.gravatar.com"), "gravatar.duoshuo.com", $avatar);

	// Replacement for the HTTPS protocol to HTTP protocol, 替换为 https 协议为 http 协议.

	$avatar = str_replace("https:", "http:", $avatar);

	return $avatar;

}

add_filter('get_avatar', 'cwyyprog_wordpress_duoshuo_avatar');
function modify_jquery() {global $wp_scripts;
	if (!is_admin()) {
		$jquery_ver = $wp_scripts->registered['jquery']->ver;
		$jquery_migrate_ver = $wp_scripts->registered['jquery-migrate']->ver;
		wp_deregister_script('jquery');
		wp_deregister_script('jquery-migrate');
		wp_enqueue_script('jquery', 'https://code.jquery.com/jquery-'.$jquery_ver.'.min.js', false, null,true);
		wp_enqueue_script('jquery-migrate', 'https://code.jquery.com/jquery-migrate-'.$jquery_migrate_ver.'.min.js', false, null,true);
		}
}
add_action('wp_enqueue_scripts', 'modify_jquery',9999);
?>
